﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;

using System.Windows;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Forms;

using DreamIn.Structures;
using DreamIn.Structures.SearchEngine;
using DreamIn.Structures.Utils;
namespace DreamIn.GUI
{
    /// <summary>
    /// Interaction logic for DreamIn.xaml
    /// </summary>
    public partial class DreamWindow : Window
    {
	    private FolderBrowserDialog folderBrowserDialog1;
        public DreamWindow()
        {
            InitializeComponent();
			//menuGrid.Opacity=0;
			opGrid.Opacity=0;
            StartSearching(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures));
        }

        #region FileSearching //Bogdi
        Timer loadTimer;
        FileSearch x;
        ThreadSafeList<Album> albums;
        private void StartSearching(String folderName)
        {
            loadTimer = new Timer();
            loadTimer.Interval = 100;
            loadTimer.Tick += new EventHandler(timer_Tick);

            List<String> dirs = new List<string>();
            dirs.Add(folderName);
            //dirs.Add("L:\\Poze\\");
            //dirs.Add(@"D:\Poze Cori\poze alexandra");
            //dirs.Add(@"D:\Bogdi\Pictures\");
            x = new FileSearch();
            albums = x.GetAllAlbums(dirs);
            loadTimer.Start();
        }
        private void timer_Tick(object sender, EventArgs e)
        {
            if (x != null && x.FileSearchCompleted())
            {
                loadTimer.Stop();
                pictureCarousel.FillCarousel(albums);
				//pictureCarousel.FillCarousel(albums[0].Pictures);
                //carousel.FillCarousel(albums[0].Pictures);
            }
            else
            {
            }
        }
        private void Window_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            try
            {
                this.DragMove();
            }
            catch (Exception ex)
            {
            }
        	// TODO: Add event handler implementation here.
        }


        private void Grid_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
			menuGrid.Opacity=100;
        	// TODO: Add event handler implementation here.
        }

        private void menuGrid_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
			//menuGrid.Opacity=0;
        	// TODO: Add event handler implementation here.
        }
        #endregion
        private void opGrid_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
        	opGrid.Opacity=100;
        }

        private void opGrid_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
        	opGrid.Opacity=0;
        }

        private void maxButton_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (this.WindowState != WindowState.Maximized)
                this.WindowState = WindowState.Maximized;
            else
                this.WindowState = WindowState.Normal;
        }

        private void minButton_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (this.WindowState != WindowState.Minimized)
                this.WindowState = WindowState.Minimized;
            else
                this.WindowState = WindowState.Normal;
        }

        private void closeButton_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
        	this.Close();
        }

        private void searchButton_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {

            this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
            // Show the FolderBrowserDialog.
            this.folderBrowserDialog1.Description ="Select the directory that you want to use for searching.";

            DialogResult result = folderBrowserDialog1.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                String folderName = folderBrowserDialog1.SelectedPath;
                StartSearching(folderName);
            }
        }

        private void backButton_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
        	pictureCarousel.GoToPrevious();
			// TODO: Add event handler implementation here.
        }

        private void nextButton_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
        	pictureCarousel.GoToNext();
			// TODO: Add event handler implementation here.
        }
    }
}
